extends ./layout/layout

block css
  style.
    #main .layui-container {
      margin-bottom: 15px;
      margin-top: 76px;
      border-radius: 2px;
      background-color: #fff;
      box-shadow: 0 1px 2px 0 rgba(0, 0, 0, .05);
      border: 1px solid #fff;

    }
    .article-add {
      padding-top: 7.5px;
    }

    .layui-form .layui-form-label{
      width: 110px;
      padding: 8px 15px;
      height: 38px;
      line-height: 20px;
      border: 1px solid #e6e6e6;
      border-radius: 2px 0 0 2px;
      text-align: center;
      background-color: #FBFBFB;
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
      box-sizing: border-box;
    }

    .layui-tab-title{
      margin-bottom: 20px;
    }

block contents
  #main
    .layui-container
      .article-add.layui-form
        .layui-tab.layui-tab-brief(lay-filter="user")
          ul.layui-tab-title
            li.layui-this 文章编辑
          #editing.layui-form.layui-form-content
            .layui-tab-item.layui-show
              form(action="/article", method="POST")
                .layui-row.layui-col-space15.layui-form-item
                  .layui-col-md3
                    label.layui-form-label 文章分类
                    .layui-input-block
                      select(lay-verify="required", name="tips", lay-filter="column")
                        option
                        option(value="nodejs") nodejs
                        option(value="vue") vue
                        option(value="react") react
                        option(value="angular") angular
                      //- .layui-unselect.layui-form-select
                      //-   .layui-select-title
                      //-     input(type="text", placeholder="请选择," value="", readonly="").layui-input.layui-unselect
                      //-     i.layui-edge
                      //-   dl.layui-anim.layui-anim-upbit
                      //-     dd(lay-value="").layui-select-tips.layui-this 请选择
                      //-     dd(lay-value="nodejs") nodejs
                      //-     dd(lay-value="vue") vue
                      //-     dd(lay-value="react") react
                      //-     dd(lay-value="angular") angular
                  .layui-col-md9
                    label(for="L_title").layui-form-label 标题
                    .layui-input-block
                      input(type="text", name="title" required="", lay-verify="required" autocomplete="off")#L_title.layui-input
                .layui-form-item.layui-form-text
                  textarea(style="display: none;")#article-content

          .layui-form-item
            button(lay-filter="send" lay-submit).layui-btn 立即发布
          


          

block scripts
  script.
    layui.use(['form', 'layedit', "element"], function() {
      const form = layui.form;
      const layedit = layui.layedit;
      const $ = layui.$

      const index = layedit.build('article-content', {
        hideTool: [
          'image' //插入图片
        ]
      }); //建立编辑器

      form.on("submit(send)", (res) => {
        const { tips, title } = res.field

        if(layedit.getText(index).trim().length === 0)return layer.alert("请输入内容")
        
        const data = {
          tips,
          title,
          content: layedit.getContent(index)
        }

        $.post("/article", data, (msg) => {
          if(msg.status){
            layer.alert('发表成功', (res) => {
              location.href = "/"
            })
          }else{
            layer.alert(`发表失败，失败信息：${msg.msg}`)
          }
        })
      })


      //- let res = 0

      //- const proving = () => {
      //-   const sym = ["+", '-', '*', '/']

      //-   let num1 = parseInt(Math.random()*100)
      //-   let num2 = parseInt(Math.random()*100)

      //-   let str = num1 + sym[parseInt(Math.random() * (sym.length - 1))] + num2

      //-   $(".result").html(str)
      //-   res = eval(str)
      //- }
      //- proving()
      //- // 验证
      //- $("button").on("click", () => {
      //-   if($("#L_vercode").val()*1 === res){

      //-   }
      //- })

    });